package com.example.mvvm.view;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;

import com.example.mvvm.viewModel.BaseViewModel;

import org.jetbrains.annotations.NotNull;

public abstract class BaseFragment <VM extends BaseViewModel,VD extends ViewDataBinding> extends Fragment {
    protected VM mViewModel;
    protected VD mDataBinding;
    protected abstract int getLayoutId();
    protected abstract void init();
    protected abstract VM getViewModel();

    @Nullable
    @org.jetbrains.annotations.Nullable
    @Override
    public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        mViewModel = getViewModel();
        mDataBinding = DataBindingUtil.inflate(inflater,getLayoutId(),container,false);
        init();
        return mDataBinding.getRoot();

    }
}
